package com.ricchieri.service;

import java.util.ArrayList;
import java.util.List;

import com.ricchieri.bean.ReservationOperatorBean;
import com.ricchieri.filter.ReservationFilter;
import com.ricchieri.filter.UserFilter;
import com.ricchieri.model.User;
import com.ricchieri.service.interf.IReportService;
import com.ricchieri.service.interf.IReservationService;
import com.ricchieri.service.interf.IUserService;

public class ReportService implements IReportService {

	IReservationService reservationService;
	IUserService userService;
	
	@Override
	public List<ReservationOperatorBean> getReservationByOperator(ReservationFilter filter) {
		UserFilter userFilter;
		User user;
		ReservationOperatorBean reservationOperatorBean;
		List<ReservationOperatorBean> list = new ArrayList<ReservationOperatorBean>();
		
		List<Object[]> count = getReservationService().getCountReservationByOperator(filter);
		
		for (Object[] objects : count) {
			userFilter = new UserFilter();
			userFilter.setId((Integer) objects[0]);
			user = getUserService().getUserById(userFilter);
			
			reservationOperatorBean = new ReservationOperatorBean();
			reservationOperatorBean.setCount(Integer.valueOf(((Long) objects[1]).intValue()));
			reservationOperatorBean.setUser(user);
			list.add(reservationOperatorBean);
		}
		
		return list;
	}

	public IReservationService getReservationService() {
		return reservationService;
	}

	public void setReservationService(IReservationService reservationService) {
		this.reservationService = reservationService;
	}

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	
}
